package packet

import "fmt"

// type maplePacket
type maplePacket []byte

func (p maplePacket) String() string {
	return fmt.Sprintf("Packet(%d): % X", p.Size(), []byte(p))
}

type maplePacketReader struct {
	pos uint16
	maplePacket
}

type packetError struct {
	need int
	left int
}

func (e *packetError) Error() string {
	return fmt.Sprintf("Tried to read %d bytes with %d bytes left to read.", e.need, e.left)
}

func NewPacketWriter() PacketWriter {
	pw := NewPacketWriterWithCapacity(32)
	return pw
}

func NewPacketWriterWithCapacity(capacity int) PacketWriter {
	mp := make(maplePacket, 0, capacity)
	return &mp
}

func NewPacketReader(data []byte) PacketReader {
	pr := maplePacketReader{0, data}
	return &pr
}

func newPacketError(need int, left int) packetError {
	return packetError{need, left}
}
